package com.stylefeng.guns.common.service.redis.Idgenerator;

import com.stylefeng.guns.common.service.redis.RedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class IdGeneratorConfig {

    @Autowired
    private RedisClient redisClient;

    @Bean
    public IdGenConfig buildIdGenConfig(){
        IdGenConfig idGenConfig = new IdGenConfig();
        idGenConfig.setLength(20);
        return idGenConfig;
    }

    @Bean
    public RedisUniqueNumberProducer buildCodisUniqueNumberProducer(){
        return new RedisUniqueNumberProducer(redisClient,"yjstockSeqNo",buildIdGenConfig());
    }

    @Bean
    public OrderIdGenerator idGenerator(){
        return new OrderIdGenerator(buildCodisUniqueNumberProducer(),buildIdGenConfig());
    }
}
